package com.sunwayworld.basemodule.rm.train.exam.resource.impl;

import com.sunwayworld.basemodule.rm.train.exam.bean.LimsCoreExamBean;
import com.sunwayworld.basemodule.rm.train.exam.bean.LimsCoreExamQuestionBean;
import com.sunwayworld.basemodule.rm.train.exam.resource.LimsCoreExamResource;
import com.sunwayworld.basemodule.rm.train.exam.service.LimsCoreExamQuestionService;
import com.sunwayworld.basemodule.rm.train.exam.service.LimsCoreExamService;
import com.sunwayworld.basemodule.rm.train.exam.validator.LimsCoreExamActivatableValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.sunwayworld.framework.data.page.Pagination;
import com.sunwayworld.framework.log.annotation.Log;
import com.sunwayworld.framework.log.annotation.LogModule;
import com.sunwayworld.framework.log.annotation.LogType;
import com.sunwayworld.framework.mybatis.mapper.MatchPattern;
import com.sunwayworld.framework.mybatis.mapper.SearchFilter;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import com.sunwayworld.framework.support.activatable.resource.AbstractGenericActivatableResource;
import com.sunwayworld.framework.support.base.resource.AbstractGenericResource;
import com.sunwayworld.framework.support.choosable.resource.AbstractGenericChoosableResource;
import com.sunwayworld.framework.validator.data.annotation.ValidateDataWith;

@LogModule("试卷")
@RestController
@GikamBean
public class LimsCoreExamResourceImpl implements LimsCoreExamResource,
                                             AbstractGenericResource<LimsCoreExamService, LimsCoreExamBean, Long>,
                                             AbstractGenericActivatableResource<LimsCoreExamService, LimsCoreExamBean, Long>,
                                             AbstractGenericChoosableResource<LimsCoreExamService, LimsCoreExamBean, Long> {

    @Autowired
    private LimsCoreExamService limsCoreExamService;
    
    @Autowired
    private LimsCoreExamQuestionService limsCoreExamQuestionService;

    @Override
    public LimsCoreExamService getService() {
        return limsCoreExamService;
    }
    
    @Log(value = "删除试卷", type = LogType.DELETE)
    @Override
    public void delete(RestJsonWrapperBean wrapper) {
        limsCoreExamService.delete(wrapper);
    }

    @Override
    @Log(value = "新增试卷题目", type = LogType.INSERT)
    public void insertQuestion(RestJsonWrapperBean wrapper) {
        limsCoreExamQuestionService.insert(wrapper);
    }

    @Override
    @Log(value = "删除试卷题目", type = LogType.DELETE)
    public void deleteQuestion(RestJsonWrapperBean wrapper) {
        limsCoreExamQuestionService.delete(wrapper);
    }

    @Override
    @Log(value = "根据试卷查询试卷题目", type = LogType.SELECT)
    public Pagination<LimsCoreExamQuestionBean> selectExamQuestionPaginationByExamId(Long id, RestJsonWrapperBean wrapper) {
        return (Pagination<LimsCoreExamQuestionBean>) limsCoreExamQuestionService.selectPaginationByFilter(SearchFilter.instance().match("EXAMID", id).filter(MatchPattern.EQ), wrapper);
    }
    
    @Override
    @Log(value = "锁定(发布)试卷", type = LogType.ACTIVATE)
    @ValidateDataWith(LimsCoreExamActivatableValidator.class)
    public void activate(RestJsonWrapperBean wrapper) {
        getService().activate(wrapper);
    }

}